<template>
  <div class="header">
    <router-link
      tag="div"
      to="/"
      v-show="showAbs"
      class="header-abs">
      <div class="iconfont banner-back">&#xe624;</div>
    </router-link>
    <div class="header-fixed">
      <div class="header-top" :style="opacityStyle">
        <router-link to="/">
          <div class="header-left">
            <span class="iconfont">&#xe624;</span>
          </div>
        </router-link>
        <h1>城市选择</h1>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'DetailHeader',
  data () {
    return {
      showAbs: true,
      opacityStyle: {
        opacity: 0
      }
    }
  },
  methods: {
    handleScroll () {
      var scrollTop = document.documentElement.scrollTop
      if (scrollTop > 10) {
        this.showAbs = false
        if (scrollTop < 140) {
          var opacity = (scrollTop - 10) / 100
          this.opacityStyle.opacity = opacity
        }
      } else {
        this.showAbs = true
      }
    }
  },
  activated () {
    window.addEventListener('scroll', this.handleScroll)
  },
  deactivated () {
    window.removeEventListener('scroll', this.handleScroll)
  }
}
</script>

<style scoped lang="less">
@import "~styles/varibles";
.header-abs{
  position: fixed;
  top: 0.1rem;
  left: 0.1rem;
  width: 0.72rem;
  height: 0.72rem;
  border-radius: 0.36rem;
  background-color: rgba(0, 0, 0, 0.5);
  .banner-back{
    line-height: 0.72rem;
    text-align: center;
  }
  color: white;
  z-index: 1;
}
.header-top{
  position: fixed;
  top: 0;
  width: 100%;
  line-height: 0.88rem;
  background-color: @bgColor;
  .header-left{
    height: 0.88rem;
    width: 0.64rem;
    float: left;
    text-align: center;
    .iconfont{
      margin-left: 0.1rem;
      color: white;
    }
  }
  h1{
    height: 0.88rem;
    margin: 0 1rem;
    text-align: center;
    font-size: 0.32rem;
    color: #fff;
  }
}
</style>
